<?php

namespace mpend\modules\passport\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\passport\models\SecurityEnvCheckForm;
use mpend\modules\passport\models\AccountForm;

/**
 * 短信验证码校验
 * @author emhome <emhome@163.com>
 * @since 2.0
 */
class AccountController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['POST'],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * 校验短信验证码
     * @return mixed
     */
    public function actionCheck() {
        $model = new SecurityEnvCheckForm();
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('安全验证失败');
        }
        $model->user_id = $this->uid;
        return $model->check();
    }

    /**
     * 帐号名验证
     * @return mixed
     */
    public function actionUpdate() {
        $model = new AccountForm($this->uid);
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请输入帐号信息');
        }
        return $model->save();
    }

}
